# This script reads the List of Stock file 
# "Anlageuniversum_US_CA.csv and inserts the contents
# into vadb db va_Wikifolio.stockname

file <- "/home/voellenk/stratlab_workdir/stratlab/wikifolio/Anlageuniversum_US_CA.csv"

listOfStocks <- read.csv(file, sep=";")

con <- connectToVadb(dbname="va_wikifolio")

sqlcmd <- function(row) {
  sql<-"INSERT INTO `va_wikifolio`.`stockname` (`name`,`symbol`,`WKN`,`ISIN`)"
  sql<-paste(sql, sprintf("VALUES ('%s','%s','%s','%s')",
                          row[,3], row[,4], row[,1], row[,2]))
  return(sql)
}

for (i in 1:nrow(listOfStocks)) {
  print(i)
  dbSendQuery(con, sqlcmd(listOfStocks[i,]))
}

disconnectFromVadb(con)